<?php /* Smarty version Smarty3-RC3, created on 2013-10-11 09:46:29
         compiled from ".\templates\billBookAdd.tpl" */ ?>
<?php /*%%SmartyHeaderCode:312855257c8f5c1c9b9-52431916%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '8449a20648e97102184496dc902b6c7fb8cc1803' => 
    array (
      0 => '.\\templates\\billBookAdd.tpl',
      1 => 1381484789,
    ),
  ),
  'nocache_hash' => '312855257c8f5c1c9b9-52431916',
  'function' => 
  array (
  ),
  'has_nocache_code' => false,
)); /*/%%SmartyHeaderCode%%*/?>
<?php if (!is_callable('smarty_function_html_options')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_options.php';
if (!is_callable('smarty_function_html_select_date')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\function.html_select_date.php';
if (!is_callable('smarty_modifier_string_format')) include 'D:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sil1\include\Smarty\libs\plugins\modifier.string_format.php';
?><?php $_template = new Smarty_Internal_Template("header.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript">
var prevPartyFine = 0;
var prevPartyAmount = 0;
	
$(document).ready(function()
{
  $(".delete").live('click', function(event) 
  {
    $(this).parent().remove();
    setNetWeight(this);
    setTotNetWeight(this);
    totFine(this);
    setAmount(this);
    setTotAmount(this);
  });
});

function addNewRow()
{
  $('#billBook tr:last').after('<tr class="itemRow"><td><input type="text" name="particulars[]" \/><\/td><td><input type="text" name="weight[]" class="weight" onChange="setNetWeight(this)"\/><\/td><td><input type="text" name="pari[]" class="pari" onChange="setNetWeight(this)"\/><\/td><td><input type="text" name="netWeight[]" class="netWeight" \/><\/td><td><input type="text" name="touch[]" class="touch" onChange="setFine(this)"\/><\/td><td><input type="text" name="waste[]" class="waste" onChange="setFine(this)"\/><\/td><td><input type="text" name="fine[]" class="fine" \/><\/td><td><input type="text" name="particular[]" class="particular" \/><\/td><td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)"\/><\/td><td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)"\/><\/td><td><input type="text" name="amount[]" class="amount" \/><\/td><td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
<\/a><\/td><td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
<\/td><\/tr>');

}

function setNetWeight(txtObj)
{
  var row = $(txtObj).parents('.itemRow');
  var price = parseFloat(row.find('.weight').val().replace("$","")) - parseFloat(row.find('.pari').val());
  isNaN(price) ? row.find('.netWeight').val("") : row.find('.netWeight').val(price);
  setTotNetWeight();
  setFine(txtObj);
}

function setTotNetWeight()
{
  var totalWeight = 0;
  var totalpari   = 0;
  var totalNetWeight = 0;
  
  $('.weight').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalWeight += Number(price);
  });
  
  $('.pari').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalpari += Number(price);
  });
  
  $('.netWeight').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totalNetWeight += Number(price);
  });

  $('#totWeight').val(totalWeight);
  $('#totPari').val(totalpari);
  $('#totNetWeight').val(totalNetWeight);
}

function setFine(txtObj)
{
  var row = $(txtObj).parents('.itemRow');
  var price = (parseFloat(row.find('.netWeight').val()) * (parseFloat(row.find('.touch').val().replace("$","")) + parseFloat(row.find('.waste').val())) / 100);
  isNaN(price) ? row.find('.fine').val("") : row.find('.fine').val(price.toFixed(0));
  totFine();
}

function totFine()
{
  var totFine = 0;
  
  $('.fine').each(function(i)
  {
    price = $(this).val();
    if (!isNaN(price)) totFine += Number(price);
  });
  
  $('#totFine').val(totFine);
    $('#partyFine').val(parseFloat(prevPartyFine)) + parseFloat(totFine);
}

function setAmount(txtObj)
{
  var row = $(txtObj).parents('.itemRow');
  var price = parseFloat(row.find('.qty').val().replace("$","")) * parseFloat(row.find('.labour').val());
  isNaN(price) ? row.find('.amount').val("") : row.find('.amount').val(price);
  setTotAmount();
}

function setTotAmount()
{
  var totQty    = 0;
  var totLabour = 0;
  var totAmount = 0;
  
  $('.amount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totAmount += Number(price);
  });
  $('#totAmount').val(totAmount);
  $('#partyAmount').val(parseFloat(prevPartyAmount) + parseFloat(totAmount));
  
  $('.labour').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totLabour += Number(price);
  });
  $('#totLabour').val(totLabour);
  
  $('.qty').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totQty += Number(price);
  });
  $('#totQty').val(totQty);
}

  function getOldAmount()
  {
	if(document.form1.party.value > 0)
	{
      $.ajax({
	    type:"POST",
	    url:'getOldAmountVepaari.php',
	    data:
	    {
	      partyId : document.form1.party.value,
	      billNo  : document.form1.billBookNo.value,
	    },
	    success: function(response)
	    {
	    	var temp = response.split(",");
	    	prevPartyFine = temp[0];
	    	prevPartyAmount = temp[1];
	    	$('#partyFine').val(prevPartyFine);
	    	$('#partyAmount').val(prevPartyAmount);
	    	$('#fixedPartyFine').val(prevPartyFine);
	    	$('#fixedPartyAmount').val(prevPartyAmount);
	    }
    });
	}
}

function hidePrevDiv(chkObj)
{
	if(chkObj.checked)
	  $('#oldTotal').show();
	else
	  $('#oldTotal').hide();
}
</script>
<form name="form1" action="" method="post">
<input type="hidden" name="isEdit" value="<?php echo $_smarty_tpl->getVariable('isEdit')->value;?>
" />
<input type="hidden" name="billNo" value="<?php echo $_smarty_tpl->getVariable('billBookNo')->value;?>
"   />
<input type="hidden" name="billBookId" value="<?php echo $_smarty_tpl->getVariable('billBookId')->value;?>
" />
<input type="hidden" name="fixedPartyFine"   id="fixedPartyFine"   value="" />
<input type="hidden" name="fixedPartyAmount" id="fixedPartyAmount" value="" />


<center><h4><?php echo $_smarty_tpl->getVariable('l_billBook')->value;?>
</h4></center>
<?php if ($_smarty_tpl->getVariable('msg')->value!=''){?><center><span style="color:#FF0000"><b><?php echo $_smarty_tpl->getVariable('msg')->value;?>
</b></span></center><?php }?>
<div class="contentDiv">
  <table border="0" id="billBook" align="center" width="100%">
  <tr>
    <td colspan="5" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_billBookDetailId')->value;?>
 
      <input type="text" name="billBookNo" size="5" value="<?php echo $_smarty_tpl->getVariable('billBookNo')->value;?>
" readonly />&nbsp;
      <?php echo $_smarty_tpl->getVariable('l_partySelect')->value;?>
 :
      <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
      <select name="party" onChange="getOldAmount();" autofocus READONLY />
        <?php echo smarty_function_html_options(array('values'=>$_smarty_tpl->getVariable('party')->value['partyId'],'output'=>$_smarty_tpl->getVariable('party')->value['partyName'],'selected'=>$_smarty_tpl->getVariable('partyId')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

      </select>
      <?php }else{ ?>
      <select name="party" onChange="getOldAmount();" autofocus  />
        <?php echo smarty_function_html_options(array('values'=>$_smarty_tpl->getVariable('party')->value['partyId'],'output'=>$_smarty_tpl->getVariable('party')->value['partyName'],'selected'=>$_smarty_tpl->getVariable('partyId')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

      </select>
      <?php }?>
    </td>
    <td colspan="6" class="table1">
      <?php echo $_smarty_tpl->getVariable('l_billBookDate')->value;?>
 : 
      <?php echo smarty_function_html_select_date(array('prefix'=>"curDate",'start_year'=>"-2",'end_year'=>"+1",'field_order'=>"DMY",'day_value_format'=>"%02d",'time'=>$_smarty_tpl->getVariable('billDate')->value),$_smarty_tpl->smarty,$_smarty_tpl);?>

    </td>
    <td class="table1"><input type="checkbox" name="removePrev" onChange="hidePrevDiv(this);" CHECKED /></td>
  </tr>
  <tr class="table1">
    <th><?php echo $_smarty_tpl->getVariable('l_particulars')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_weight')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_pari')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_netWeight')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_touch')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_waste')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_fine')->value;?>
</th>
    <th>Particular</th>
    <th><?php echo $_smarty_tpl->getVariable('l_qty')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_labour')->value;?>
</th>
    <th><?php echo $_smarty_tpl->getVariable('l_amount')->value;?>
</th>
    <th colspan="2">&nbsp;</th>
  </tr>
  <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
    <?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['name'] = "sec";
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'] = is_array($_loop=count($_smarty_tpl->getVariable('billBookArr')->value)) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']["sec"]['total']);
?>
      <tr class="itemRow">
        <td><input type="text" name="particulars[]" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['particulars'];?>
" /></td>
        <td><input type="text" name="weight[]" class="weight" onChange="setNetWeight(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['weight'];?>
" /></td>
        <td><input type="text" name="pari[]" class="pari" onChange="setNetWeight(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['pari'];?>
" /></td>
        <td><input type="text" name="netWeight[]" class="netWeight" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['netWeight'];?>
" /></td>
        <td><input type="text" name="touch[]" class="touch" onChange="setFine(this)" value="<?php echo smarty_modifier_string_format($_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['touch'],"%.0f");?>
" /></td>
        <td><input type="text" name="waste[]" class="waste" onChange="setFine(this)" value="<?php echo smarty_modifier_string_format($_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['waste'],"%.0f");?>
" /></td>
        <td><input type="text" name="fine[]" class="fine" value="<?php echo smarty_modifier_string_format($_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['fine'],"%.2f");?>
" /></td>
        <td><input type="text" name="particular[]" class="particular" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['particular'];?>
" /></td>
        <td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['qty'];?>
" /></td>
        <td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['labour'];?>
" /></td>
        <td><input type="text" name="amount[]" class="amount" value="<?php echo $_smarty_tpl->getVariable('billBookArr')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec']['index']]['amount'];?>
" /></td>
        <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
         <td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
</td>
      </tr>
    <?php endfor; endif; ?>
  <?php }else{ ?>
  <tr class="itemRow">
    <td><input type="text" name="particulars[]" /></td>
    <td><input type="text" name="weight[]" class="weight" onChange="setNetWeight(this)"/></td>
    <td><input type="text" name="pari[]" class="pari" onChange="setNetWeight(this)"/></td>
    <td><input type="text" name="netWeight[]" class="netWeight" /></td>
    <td><input type="text" name="touch[]" class="touch" onChange="setFine(this)"/></td>
    <td><input type="text" name="waste[]" class="waste" onChange="setFine(this)"/></td>
    <td><input type="text" name="fine[]" class="fine" /></td>
    <td><input type="text" name="particular[]" class="particular" /></td>
    <td><input type="text" name="qty[]" class="qty" onChange="setAmount(this)"/></td>
    <td><input type="text" name="labour[]" class="labour" onChange="setAmount(this)"/></td>
    <td><input type="text" name="amount[]" class="amount" /></td>
    <td><a href="javascript:addNewRow();"><?php echo $_smarty_tpl->getVariable('l_add')->value;?>
</a></td>
    <td class="delete"><?php echo $_smarty_tpl->getVariable('l_remove')->value;?>
</td>
    <td>&nbsp;</td>
  </tr>
  <?php }?>
  </table>
  
  <table width="100%">
    <tr class="itemRowTot">
      <th><?php echo $_smarty_tpl->getVariable('l_total')->value;?>
</th>
      <th><input type="text" name="totWeight" id="totWeight"/></th>
      <th><input type="text" name="totPari" id="totPari"/></th>
      <th><input type="text" name="totNetWeight" id="totNetWeight"/></th>
      <th align="right" width="105px;">&nbsp;</th>
      <th align="right" width="105px;">&nbsp;</th>
      <th><input type="text" name="totFine" id="totFine"/></th>
      <th><input type="text" name="totQty" id="totQty"/></th>
      <th><input type="text" name="totLabour" id="totLabour"/></th>
      <th><input type="text" name="totAmount" id="totAmount"/></th>
      <th colspan="2" width="70px;"></th>
    </tr>
  </table>
  <div id="oldTotal" style="float:right;">
  	<b>Prev. Fine</b> <input type="text" name="partyFine" id="partyFine" />
  	<b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' />
  </div>
  <?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
    <input type="submit" name="billBookAddBtn" value="<?php echo $_smarty_tpl->getVariable('l_save')->value;?>
"/>
    <input type="submit" name="cancelBtn" value="Cancel"/>
  <?php }else{ ?>
    <input type="submit" name="billBookAddBtn" value="<?php echo $_smarty_tpl->getVariable('l_addBillBook')->value;?>
"/>
  <?php }?>
</div>
</form>
<script type="text/javascript">
<?php if ($_smarty_tpl->getVariable('isEdit')->value==1){?>
  setTotNetWeight();
  totFine();
  setTotAmount();
<?php }?>  
</script>
<?php $_template = new Smarty_Internal_Template("footer.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>